package org.example.rabbitmq.server.route.strategy.impl;

import org.example.rabbitmq.config.MultiQueueProperties;
import org.example.rabbitmq.server.route.strategy.RouteStrategy;
import org.example.rabbitmq.vo.RoutingKey;
import org.example.rabbitmq.vo.TenantId;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

public class MappingRouteStrategy implements RouteStrategy {
    @Autowired
    MultiQueueProperties multiQueueProperties;
    Map<Long, Integer> indexMap;

    public MappingRouteStrategy(Map<Long, Integer> indexMap) {
        this.indexMap = indexMap;
    }

    @Override
    public RoutingKey route(TenantId tenantId) {
        int index = indexMap.get(tenantId.getId());
        return new RoutingKey(multiQueueProperties.getRoutingKeyWithIndex(index));
    }
}